package jsyf.oa.web.Bonus;


import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.task.BonusFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(value = "查询组建奖惩", description = "查询组建奖惩")
@Controller
@RequestMapping("/bonus")
public class BonusController {
    @Resource
    private BonusFacade bonusFacade;

    @RequestMapping(value = "/getBonus.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "获取组建金额列表",
            notes = "获取组建金额列表",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void getBonus(HttpServletResponse response, @RequestBody String jsonData) {
        List<JSONObject> result = this.bonusFacade.getBonus(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(result));
    }

    @RequestMapping(value = "/updateBonusMoney.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "更新金额",
            notes = "更新金额",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    public void updateBonusMoney(HttpServletResponse response, @RequestBody String jsonData) {
        Boolean result = this.bonusFacade.updateBonusMoney(jsonData);
        JSONObject jsonObject =new JSONObject();
        jsonObject.put("records",result);
        if (result==true){
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(jsonObject));
        }else{
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("更新失败"));
        }
    }
}
